<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-select v-model="dataForm.province" clearable @change="proChange" placeholder="请选择省份">
          <el-option
            v-for="item in provinces"
            :key="item.cityCode"
            :label="item.cityNameZh"
            :value="item.cityCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.city" clearable @change="cityChange" placeholder="请选择城市">
          <el-option
            v-for="item in citys"
            :key="item.cityCode"
            :label="item.cityNameZh"
            :value="item.cityCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.county" clearable placeholder="请选择区域">
          <el-option
            v-for="item in countys"
            :key="item.cityCode"
            :label="item.cityNameZh"
            :value="item.cityCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item>
        <el-select v-model="dataForm.brand" clearable placeholder="请选择品牌">
          <el-option
            v-for="item in brands"
            :key="item.id"
            :label="item.bname"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-input v-model="dataForm.name" clearable placeholder="酒店名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="query()">查询</el-button>
        <el-button
          v-if="isAuth('ht:hthotelinfo:save')"
          type="primary"
          @click="addOrUpdateHandle()"
        >新增</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" v-loading="dataListLoading" style="width: 100%;">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="hotelinfo-table-expand">
            <el-form-item label="酒店编码">
              <span>{{ props.row.hotelCode }}</span>
            </el-form-item>
            <el-form-item label="酒店地址">
              <span>{{ props.row.address }}</span>
            </el-form-item>
            <el-form-item label="联系电话">
              <span>{{ props.row.phone }}</span>
            </el-form-item>
            <el-form-item label="人工校准">
              <el-tag v-if="props.row.manualVerify === 0" size="small" type="info">未校准</el-tag>
              <el-tag v-else-if="props.row.manualVerify === 1" size="small" type="success">已校准</el-tag>
            </el-form-item>
            <el-form-item label="自动下单">
              <el-tag v-if="props.row.automaticOrder === 0" size="small" type="info">人工下单</el-tag>
              <el-tag v-else-if="props.row.automaticOrder === 1" size="small" type="success">自动下单</el-tag>
            </el-form-item>
            <el-form-item label="商圈名">
              <span>{{ props.row.area }}</span>
            </el-form-item>
            <el-form-item label="描述信息">
              <span>{{ props.row.hotelInfo }}</span>
            </el-form-item>
            <el-form-item label="坐标类型">
              <el-tag v-if="props.row.axes === 'G'" size="small" type="info">谷歌</el-tag>
              <el-tag v-else-if="props.row.axes === 'B'" size="small" type="info">百度</el-tag>
              <el-tag v-else-if="props.row.axes === 'A'" size="small" type="info">高德</el-tag>
              <el-tag v-else-if="props.row.axes === 'M'" size="small" type="info">灵图</el-tag>
            </el-form-item>
            <el-form-item label="经度">
              <span>{{ props.row.axesX }}</span>
            </el-form-item>
            <el-form-item label="纬度">
              <span>{{ props.row.axesY }}</span>
            </el-form-item>
            <el-form-item label="星级">
              <el-tag v-if="props.row.starLevel === '3'" size="small" type="info">3星以下</el-tag>
              <el-tag v-else-if="props.row.starLevel === '4'" size="small" type="info">4星</el-tag>
              <el-tag v-else-if="props.row.starLevel === '5'" size="small" type="info">5星</el-tag>
              <el-tag v-else-if="props.row.starLevel === '6'" size="small" type="info">5星以上</el-tag>
            </el-form-item>
            <el-form-item label="酒店类型">
              <span>{{ props.row.typeName }}</span>
            </el-form-item>
            <el-form-item label="酒店设施">
              <span>{{ props.row.hotelFacilities }}</span>
            </el-form-item>
            <el-form-item label="酒店服务">
              <span>{{ props.row.service }}</span>
            </el-form-item>
            <el-form-item label="起价">
              <span>{{ props.row.sp }}</span>
            </el-form-item>
            <el-form-item label="开业时间">
              <span>{{ props.row.openTime }}</span>
            </el-form-item>
            <el-form-item label="装修时间">
              <span>{{ props.row.decorateTime }}</span>
            </el-form-item>
            <el-form-item label="首图信息">
              <span>{{ props.row.pictureurl }}</span>
            </el-form-item>
            <el-form-item label="品牌">
              <span>{{ props.row.bname }}</span>
            </el-form-item>
            <el-form-item label="楼层信息">
              <span>{{ props.row.floor }}</span>
            </el-form-item>
            <el-form-item label="酒店集团">
              <span>{{ props.row.htgroup }}</span>
            </el-form-item>
            <el-form-item label="数据来源">
              <el-tag v-if="props.row.dataFrom === 1" size="small" type="info">携程</el-tag>
              <el-tag v-else-if="props.row.dataFrom === 2" size="small" type="success">美团</el-tag>
              <el-tag v-else-if="props.row.dataFrom === 3" size="small" type="success">官网</el-tag>
              <el-tag v-else-if="props.row.dataFrom === 4" size="small" type="success">其他</el-tag>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column prop="hotelName" header-align="left" align="left" label="酒店名称" width="300"></el-table-column>
      <el-table-column prop="cityNameZh" header-align="left" align="left" label="所在地区" width="140"></el-table-column>
      
      <el-table-column prop="status" header-align="left" align="left" label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 0" size="small" type="success">营业中</el-tag>
          <el-tag v-else size="small" type="warning">非营业中</el-tag>
        </template>
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="250" label="操作">
        <template slot-scope="scope">
          <!-- <el-button
            type="text"
            size="small"
            v-if="isAuth('ht:hthotelinfo:addprice')"
            @click="addPrice(scope.row)"
          >加价</el-button> -->
          <el-button
            type="text"
            size="small"
            v-if="isAuth('ht:hthotelinfo:update')"
            @click="addOrUpdateHandle(scope.row.id)"
          >修改</el-button>
          <el-button
            type="text"
            size="small"
            v-if="isAuth('ht:hthotelinfo:delete')"
            @click="deleteHandle(scope.row.id)"
          >删除</el-button>
          <el-button
            type="text"
            size="small"
            v-if="isAuth('ht:hthotelinfo:viewroom')"
            @click="viewRoom(scope.row)"
          >房型</el-button>
          <el-button
            type="text"
            size="small"
            v-if="isAuth('ht:hthotelinfo:viewfrom')"
            @click="viewfrom(scope.row.id)"
          >来源</el-button>
          <el-button
            type="text"
            size="small"
            v-if="isAuth('ht:hthotelinfo:orderhotel')"
            @click="ordeHotel(scope.row.id)"
          >下单</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from './hthotelinfo-add-or-update'
import { treeDataTranslate } from '@/utils'
export default {
  data() {
    return {
      dataForm: {
        province: null,
        city: null,
        county: null,
        brand: null,
        hotelName: ''
      },
      tier: 1,
      parentId: -1,
      provinces: [],
      citys: [],
      countys: [],
      brands: [],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    }
  },
  components: {
    AddOrUpdate
  },
  activated() {
    console.log(this.$route.params.hotelName)
    if(this.$route.params.hotelName != null && this.$route.params.hotelName != undefined){
      this.dataForm.name = this.$route.params.hotelName
    }
    this.getQuryCitys()
    this.getBrands()
    // this.getDataList()
  },
  methods: {
    // 获取区域查询条件
    getQuryCitys() {
      this.$http({
        url: this.$http.adornUrl('/ht/hthotelinfo/citys'),
        method: 'post',
        params: this.$http.adornParams({
          tier: this.tier,
          parentId: this.parentId
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          switch (this.tier) {
            case 1:
              this.provinces = data.list
              break
            case 2:
              this.citys = data.list
              break
            case 3:
              this.countys = data.list
              break
          }
        }
      })
    },
    // 选择省份
    proChange(value) {
      this.parentId = value
      this.tier = 2
      this.getQuryCitys()
    },
    // 选择城市
    cityChange(value) {
      this.parentId = value
      this.tier = 3
      this.getQuryCitys()
    },
    // 查询品牌
    getBrands() {
      this.$http({
        url: this.$http.adornUrl('/ht/hthotelinfo/brand'),
        method: 'get'
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.brands = data.list
        }
      })
    },
    query(){
      this.pageIndex = 1
      this.getDataList()
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/ht/hthotelinfo/list'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          // 'province':this.dataForm.province,
          'city':this.dataForm.city,
          'county': this.dataForm.county,
          'brand': this.dataForm.brand,
          'name': this.dataForm.name
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list
          this.totalPage = data.page.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 加价
    // addPrice(data) {
    //   this.$router.push({ name: 'op-htlprice', params: { hotel: data} })
    // },
    // 查看房型
    viewRoom(data) {
      this.$router.push({ name: 'ht-htphysicalroom', params: { hotel: data } })
    },
    // 查看来源
    viewFrom(id) {
    },
    // 定酒店
    ordeHotel(id) {
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    // 删除
    deleteHandle(id) {
      var ids = id ? [id] : this.dataListSelections.map(item => {
        return item.id
      })
      this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/ht/hthotelinfo/delete'),
          method: 'post',
          data: this.$http.adornData(ids, false)
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      })
    }
  }
}
</script>
<style>
.hotelinfo-table-expand {
  font-size: 0;
}
.hotelinfo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.hotelinfo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
